@extends('backstage.layout.master')
@section('title', '产品模板定制区域列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/product-temp/product-temp-list">产品模板</a>
            </li>
            <li>
                工艺列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
            <form class="form-search">
			<span class="input-icon">
				<input type="text" placeholder="搜索..." name="search" value="{{isset($prod_temps->search)?$prod_temps->search:''}}" class="nav-search-input"
                                           id="nav-search-input" autocomplete="off"/>
				<i class="icon-search nav-search-icon"></i>
				</span>
            </form>
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                产品模板
                <small>
                    <i class="icon-double-angle-right"></i>
                </small>
                <span class="pull-right">
                <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/custom-zone-list-page?product_temp_id={{empty($_GET['product_temp_id'])?'':$_GET['product_temp_id']}}&colour_id={{empty($_GET['colour_id'])?'0':$_GET['colour_id']}}';">返回添加定制区域列表</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <h3 class="header smaller lighter red">产品模板简介：</h3>
                <div class="well">
                    <h4 class="green smaller lighter">产品模板参数</h4>
                    1、产品模板Id：{{isset($product_temp->product_temp_id)?$product_temp->product_temp_id:""}}</br>
                    2、品牌：{{isset($product_temp->brand_name)?$product_temp->brand_name:""}}</br>
                    3、产品模板名称：{{isset($product_temp->name)?$product_temp->name:""}}</br>
                    4、产品模板简介：{{isset($product_temp->description)?$product_temp->description:""}}</br>
                    5、当前颜色：{{isset($temp_colour->colour_name)?$temp_colour->colour_name:""}}</br>
                    6、设计区域：{{isset($temp_custom_zone->position_name)?$temp_custom_zone->position_name:""}}</br>
                    7、工艺：{{isset($temp_craftsmanship->craftsmanship_name)?$temp_craftsmanship->craftsmanship_name:""}}</br>
                </div>
            </div>
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="alert alert-info">
                    <i class="icon-hand-right"></i>
                    可定制颜色添加:&nbsp
                    <select id="">
                        <option selected value="sel_colour">颜色</option>
                    </select>
                    <select id="sel_colour">
                        @if(sizeof($un_sel_colours)==0)
                            暂无可选颜色~~~~~~
                        @else
                         @foreach($un_sel_colours as $un_sel_colour)
                        <option value={{isset($un_sel_colour->colour_id)?$un_sel_colour->colour_id:0}}>{{isset($un_sel_colour->colour_name)?$un_sel_colour->colour_name:''}}</option>
                         @endforeach
                        @endif
                    </select>
                    <button onclick="addCaftsmanshipColour('{{isset($temp_craftsmanship_id)?$temp_craftsmanship_id:0}}')">添加</button>
                </div>
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>区域编号</th>
                            <th>颜色名</th>
                            <th>排序</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($temp_craftsmanship_colours as $temp_craftsmanship_colour)
                            <tr class="" data-tr-id="{{$temp_craftsmanship_colour->id}}">
                                <td class="center">
                                    <label>
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{{isset($temp_craftsmanship_colour->id)?$temp_craftsmanship_colour->id:''}}</td>
                                <td>{{isset($temp_craftsmanship_colour->product_temp_craftsmanship_id)?$temp_craftsmanship_colour->product_temp_craftsmanship_id:''}}</td>
                                <td>
                                    {{isset($temp_craftsmanship_colour->colour_name)?$temp_craftsmanship_colour->colour_name:''}}
                                </td>
                                <td style="width:68px;">
                                    <input type="number" name="sort" value="{{isset($temp_craftsmanship_colour->sort)?$temp_craftsmanship_colour->sort:1}}" class="sort" style="width:50px;">
                                    <input type="hidden" value="{{isset($temp_craftsmanship_colour->sort)?$temp_craftsmanship_colour->sort:1}}">
                                    <input type="hidden" value="{{isset($temp_craftsmanship_colour->id)?$temp_craftsmanship_colour->id:''}}">
                                </td>
                                <td class="center" style="width:68px;">
                                <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                                    <a  title="删除" style="color:#d77600;cursor: pointer;" onclick="deleteCraftsmanshipColor({{isset($temp_craftsmanship_colour->id)?$temp_craftsmanship_colour->id:0}})">
                                        <i class="icon-trash bigger-130"></i>
                                    </a>
                                </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
            $(".sort").blur(function(){
                var sort = $(this).next().val();
                var newSort = $(this).val();
                var id = $(this).next().next().val();
                var a = $(this);
                if(!checkRate(newSort)){
                    swal({
                        title: "输入排序号不在0-999范围内!!！",
                        text: "",
                        type: "error",
                        timer:1000
                    });
                }else{
                    $.ajax({
                        type: "POST",
                        url: "/backstage/product-temp/update-craftsmanship-colour-sort",
                        data:{"sort":newSort,"id":id},
                        success: function(msg){
                            if(msg.state==1){
                                swal({
                                    title: "更新成功！",
                                    text: "",
                                    type: "success",
                                    timer:1000
                                });
                                location.reload();
                            }else{
                                swal({
                                    title: msg.message,
                                    text: "",
                                    type: "error",
                                    timer:1000
                                });
                            }
                        },
                        error:function(){
                            swal({
                                title: "系统繁忙！",
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    });
                }
            });

        });
        function deleteCraftsmanshipColor(id) {
            if(id==0){
                swal('获取ID出错','','warning');
                return false;
            }
            swal({
                title: "确定删除？",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },function (){
                $.ajax({
                    type: "post",
                    url: "/backstage/product-temp/delete-craftsmanship-colour",
                    data:{"id":id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state==1){
                            swal({
                                title:'删除成功！',
                                text: "",
                                type: "success",
                                timer:2000
                            });
                            $('[data-tr-id='+id+']').remove();
                        }else{
                            swal({
                                title: res.message,
                                text: "",
                                type: "error",
                                timer:3000
                            });
                        }
                    },
                    error:function(){
                        swal({
                            title: "系统繁忙！",
                            text: "",
                            type: "error",
                            timer:2000
                        });
                    }
                });//ajax
            });
        }
        var state = 0;
        function addCaftsmanshipColour(th){
            if(state == 0){
                state = 1;
                var colour_id = $("#sel_colour option:selected").val();
                console.log('colour_id:'+colour_id);
                console.log('th:'+th);
                if(th == 0 ||(colour_id==0)){
                    swal('系统繁忙稍后再试','','warning');
                    state = 0;
                    return ;
                }
                swal('处理中，请稍后','','warning');
                $.ajax({
                    type: "post",
                    url: "/backstage/product-temp/add-craftsmanship-colour",
                    data:{"product_temp_craftsmanship_id":th,"colour_id":colour_id},
                    dataType: 'json',
                    success: function(res){
                        if(res.state ==1){
                            swal('添加成功','','success');
                            setTimeout(function(){},1000);
                            location.reload();
                            return ;
                        }
                        swal(res.message,'','warning');
                    },
                    error:function(){
                        swal('系统繁忙','请稍后重试','warning');
                    }
                });
                state = 0;
            }

        }
        /***
         * 检查数据格式
         * @param input
         * @returns {boolean}
         */
        function checkRate(input)
        {
            var reg = new RegExp("^[0-9]{1,3}$");
            return reg.test(input);
        }
    </script>
@stop